package com.su.sweet.service.impl;

import cn.hutool.core.util.IdUtil;
import com.su.sweet.mapper.ActExtBindMapper;
import com.su.sweet.model.ActExtBind;
import com.su.sweet.service.ActExtBindService;
import org.apache.ibatis.solon.annotation.Db;
import org.noear.solon.annotation.Component;
import org.noear.solon.data.annotation.Tran;

import java.math.BigInteger;
import java.util.Date;

@Component
public class ActExtBindServiceImpl implements ActExtBindService {
    @Db("master")
    private ActExtBindMapper actExtBindMapper;

    @Tran
    @Override
    public BigInteger saveBindInfo(ActExtBind bindInfo) {
        if (bindInfo.getUid() == null) {
            long uid = IdUtil.getSnowflake().nextId();
            bindInfo.setUid(BigInteger.valueOf(uid));
            bindInfo.setCreateTime(new Date());
            bindInfo.setUpdateTime(new Date());
            actExtBindMapper.insert(bindInfo);
        } else {
            ActExtBind update = new ActExtBind();
            update.setUid(bindInfo.getUid());
            update.setUpdateBy(bindInfo.getUpdateBy());
            update.setFlowCode(bindInfo.getFlowCode());
            update.setUpdateTime(new Date());
            actExtBindMapper.updateById(update);
        }
        return bindInfo.getUid();
    }

    @Override
    public String selectActFlowId(String areaCode, String dataType) {
        return actExtBindMapper.selectActFlowId(areaCode, dataType);
    }
}
